<template>
    <!-- 修改资料 -->

    <div>
        <!--  v-if="visible"  @click.self="handleClose" -->
                <el-form label-width="70px" :model="form" label-position="right" ref="formRef" :rules="formRules">
                    <el-row>
                        <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
                            <el-form-item label="编号" prop="number">
                                <el-input v-model="form.number"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
                            <el-form-item label="名称" prop="name">
                                <el-input v-model="form.name"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
                            <el-form-item label="上级类别" prop="parentId">
                                <el-tree-select v-model="form.parentId" :data="parentData" :render-after-expand="false"
                                    :check-strictly=true />
                            </el-form-item>
                        </el-col>
                        <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
                            <el-form-item label="状态" prop="status" >
                                <el-radio-group v-model="form.status"  style="margin-top: -4px;">
                                    <el-radio label="normal" size="large">启用</el-radio>
                                    <el-radio label="disable" size="large">停用</el-radio>
                                </el-radio-group>
                             </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="24">
                            <el-form-item label="备注" prop="remark">
                                <el-input v-model="form.remark"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-form>
                <div class="button-position">
                    <el-button @click="updateVisible">取 消</el-button>
                    <el-button type="primary" @click="update(formRef)">确 定</el-button>
                </div>
    </div>
</template>

<script setup>
import { reactive, ref,onMounted } from 'vue';
import { ElNotification} from 'element-plus';
import Api from '@/api/model/meta'
const emit = defineEmits(['updatetable'])

const visible = ref(true)
// 添加用户数据的对象
const form = ref({
    number: '',
    name: '',
    parentId:'',
    status:'',
    remark:''
});
const props = defineProps({
    paramsData: {
        type: Object,
        defalut: {}
    }
})  
const parentData =ref()
const formRef = ref()
const formRules = reactive({
    number: [
        { required: true, message: "请输入编号", trigger: "blur" },
    ],
    name: [
        { required: true, message: "请输入名称", trigger: "blur" },
    ]
})

onMounted(() => {
    getInit()
})

const updateVisible = () => {
    emit('updatetable')
}


const getInit = async () => {
    let params = {
        fileName:'MetaCatalogTreeReport'
    }
    let res = await Api.Catalog.parentTree.post(params);
    parentData.value = res.reportData
    let detailres = await Api.Catalog.detail.post(props.paramsData);
    form.value = detailres.data
}

// 上传
const update = async (formRef) => {
    await formRef.validate((valid, fields) => {
        if (valid) {
            updateData();
        }
    })
}
const restAddFormData = () => {
    formRef.value.resetFields();
}
const updateData = async () => {
    // console.log(form.name);
    var params = {
        bean: form.value,
    }
    var res = await Api.Catalog.update.post(params);
    if (res.code == 200) {
        restAddFormData();
        ElNotification.success({ title: '', message: '添加成功！', duration: 2000 });
        emit('updatetable',true)
    }
}

</script>

<style scoped></style>

